package com.ts.api.http.platform.biz;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.algorithm.encrypt.symmetric.AES;
import com.gitee.apanlh.util.base.*;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.gitee.apanlh.web.http.HttpContentType;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.common.entity.ApiParameter;
import com.ts.api.common.util.H5DomainUrlUtils;
import com.ts.api.http.platform.entity.apply.ApiPlatApplyHuiRongQianBao;
import com.ts.api.http.platform.entity.dataexchange.ApiPlatDataExchangeHuiRongQianBao;
import com.ts.api.module.api.convert.core.annotation.ApiPlan;
import com.ts.api.module.api.convert.core.annotation.ApiPlanConvertType;
import com.ts.api.module.api.convert.core.entity.ApiApplyParameter;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.core.entity.ApiDataExchangeParameter;
import com.ts.api.module.api.convert.core.utils.ApiFieldConverter;
import com.ts.api.module.api.convert.platform.entity.RespPlatformMultiPhoneMaskDataExchange;
import com.ts.api.module.api.convert.platform.entity.RespPlatformNoticeApply;
import com.ts.api.module.api.convert.platform.entity.RespPlatformPhoneMaskApply;
import com.ts.api.module.api.convert.platform.entity.RespPlatformPhoneMaskDataExchange;
import com.ts.api.module.api.convert.platform.handler.ApiPlatformPhoneMaskConvertHandler;
import com.ts.api.module.api.entity.ApiProtocol;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 安心分期-V3&惠融钱包 全cps80
 * 文档：<a href="https://fz6gwn68j3.feishu.cn/docx/GoBzdPMoQoH58lxfgAJc76PrnBh?302from=wiki">...</a>
 * 密码：#12E8233
 *
 * @author 李源聪
 */
@ApiPlan(productId = "151", type = ApiPlanConvertType.PLAT_PHONE_MASK)
public class ApiPlatHuiRongQianBaoPhoneMaskConvert implements ApiPlatformPhoneMaskConvertHandler {

    private static final String KEY = "yUs3htGH76HmU8Jx";
    private static final String IV = "yUs3htGH76HmU8Jx";
    private static final String CHANNEL_CODE = "axfqymxcxhr";

    @Override
    public RespPlatformMultiPhoneMaskDataExchange respDataExchange(String respJson) {
        JSONObject Object = JsonUtils.get(respJson);
        if (Object == null) {
            return RespPlatformMultiPhoneMaskDataExchange.ofFail();
        }
        if (!Eq.str(Object.getString("code"), "200")) {
            return RespPlatformMultiPhoneMaskDataExchange.ofFail();
        }
        if (!Eq.str(Object.getJSONObject("data").getString("status"), "1")) {
            return RespPlatformMultiPhoneMaskDataExchange.ofFail();
        }

        RespPlatformMultiPhoneMaskDataExchange respPlatformMultiPhoneMaskDataExchange = RespPlatformMultiPhoneMaskDataExchange.ofSuc();
        List<RespPlatformPhoneMaskDataExchange> listRespPlatformPhoneMaskDataExchange = CollUtils.newArrayList();
        JSONArray resData = JsonUtils.get(respJson).getJSONArray("data");
        for (int i = 0; i < resData.size(); i++) {
            JSONObject item = resData.getJSONObject(i);
            if (ValidParam.isNotNull(item)) {
                JSONObject product = item.getJSONArray("product").getJSONObject(0);
                BigDecimal price = product.getBigDecimal("price");
                String companyName = product.getString("companyName");
                String productName = product.getString("productName");
                String productId = product.getString("productId");

                List<String> listPhoneMd5 = CollUtils.newArrayList(newList -> {
                    JSONArray jsonArray = product.getJSONArray("md5List");
                    IteratorUtils.array(jsonArray, (protocolResult, index) -> {
                        String phoneMd5 = jsonArray.getString(index);
                        newList.add(phoneMd5);
                    });
                });
                String logo = product.getString("logo");

                //  添加协议
                List<ApiProtocol> listProtocol = CollUtils.newArrayList(newList -> {
                    //  获取协议
                    JSONArray listProtocolResult = product.getJSONArray("agreements");
                    IteratorUtils.array(listProtocolResult, (protocolResult, index) -> {
                        JSONObject protocolObject = listProtocolResult.getJSONObject(index);
                        ApiProtocol protocol = new ApiProtocol();
                        protocol.setProtocolName(protocolObject.getString("showName"));
                        protocol.setProtocolUrl(protocolObject.getString("showUrl"));
                        newList.add(protocol);
                    });
                });

                RespPlatformPhoneMaskDataExchange respPlatformPhoneMaskDataExchange = RespPlatformPhoneMaskDataExchange.of();
                respPlatformPhoneMaskDataExchange.setPrice(price);
                respPlatformPhoneMaskDataExchange.setLogoPath(logo);
                respPlatformPhoneMaskDataExchange.setDisplayName(companyName);
                respPlatformPhoneMaskDataExchange.setProductName(productName);
                respPlatformPhoneMaskDataExchange.setProtocolList(listProtocol);
                respPlatformPhoneMaskDataExchange.setApplyId(productId);
                respPlatformPhoneMaskDataExchange.setListPhoneMd5(listPhoneMd5);
                listRespPlatformPhoneMaskDataExchange.add(respPlatformPhoneMaskDataExchange);
            }
        }
        respPlatformMultiPhoneMaskDataExchange.setListPhoneMask(listRespPlatformPhoneMaskDataExchange);
        return respPlatformMultiPhoneMaskDataExchange;
    }

    @Override
    public RespPlatformNoticeApply parseApplyNotice(RequestVO requestVO) {
        return null;
    }

    @Override
    public Map<String, Object> respApplyNotice(ApiBizStatus apiBizStatus) {
        return Map.of();
    }

    @Override
    public Object dataExchange(ApiDataExchangeParameter apiDataExchangeParameter) throws Exception {
        ApiParameter apiParameter = ApiParameter.create();
        apiParameter.put("ReqId", apiDataExchangeParameter.getReqId());
        apiDataExchangeParameter.setHttpContentType(HttpContentType.APPLICATION_JSON);
        ApiPlatDataExchangeHuiRongQianBao data = new ApiPlatDataExchangeHuiRongQianBao();
        // 请求编号：渠道编号+时间毫秒数
        data.setRequestId(CHANNEL_CODE + "+" + apiDataExchangeParameter.getReqId());
        // 姓名 需传全名
        data.setUserName("浩安星");
        ApiFieldConverter apiFieldConverter = ApiFieldConverter.create(apiDataExchangeParameter);
        // 性别 男/女
        data.setSex(apiFieldConverter.getSexText());
        data.setAge(apiFieldConverter.getAgeInt());
        // 手机号前8位明文
        data.setPhoneMask(apiDataExchangeParameter.getPhoneMask());
        // 学历 :-1.初中及以下 0.高中/中专 1.大专 2.本科 3.硕士 4.博士
        if (ValidParam.isNotEmpty(apiDataExchangeParameter.getEducationAttainment())) {
            Integer value = ChooseEq.create()
                    .when(apiDataExchangeParameter.getEducationAttainment(), "1", -1)
                    .when(apiDataExchangeParameter.getEducationAttainment(), "2", 0)
                    .when(apiDataExchangeParameter.getEducationAttainment(), "3", 0)
                    .when(apiDataExchangeParameter.getEducationAttainment(), "4", 1)
                    .when(apiDataExchangeParameter.getEducationAttainment(), "5", 2)
                    .when(apiDataExchangeParameter.getEducationAttainment(), "6", 3)
                    .end(-1);
            data.setEducation(value);
        }
        // 城市编码
        data.setCity(Integer.parseInt(apiDataExchangeParameter.getAreaCode()));
        Integer money = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanAmount(), "1", 3)
                .when(apiDataExchangeParameter.getLoanAmount(), "2", 5)
                .when(apiDataExchangeParameter.getLoanAmount(), "3", 10)
                .when(apiDataExchangeParameter.getLoanAmount(), "4", 20)
                .end();
        data.setLoanAmt(money);
        // 期限：1. 1个月 2. 3个月 3. 6个月 4. 9个月 5. 12个月 6. 24个月 7. 36个月 8. 36个月以上 默认 12个月
        data.setLoanTerm(5);
        // 用途：1.购车贷款 2.购房贷款 3.装修贷款 4.教育贷款 5.消费贷款 6.过桥贷款 7.结婚贷款 8.旅游贷款 9.医疗贷款 10.其他贷款
        Integer loanPurpose = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanPurpose(), "1", 8)
                .when(apiDataExchangeParameter.getLoanPurpose(), "2", 4)
                .when(apiDataExchangeParameter.getLoanPurpose(), "3", 7)
                .when(apiDataExchangeParameter.getLoanPurpose(), "4", 3)
                .when(apiDataExchangeParameter.getLoanPurpose(), "5", 9)
                .when(apiDataExchangeParameter.getLoanPurpose(), "6", 10)
                .end(10);
        data.setLoanUse(loanPurpose);
        // 社保： 0.无社保 1.缴纳未满6个月 2.缴纳6个月以上
        Integer social = ChooseEq.create()
                .when(apiDataExchangeParameter.getSocialSecurity(), "1", 0)
                .when(apiDataExchangeParameter.getSocialSecurity(), "2", 1)
                .when(apiDataExchangeParameter.getSocialSecurity(), "3", 2)
                .when(apiDataExchangeParameter.getSocialSecurity(), "4", 1)
                .end(0);
        data.setSocial(social);
        // 公积金： 0.无公积金 1.缴纳未满6个月 2.缴纳6个月以上
        Integer fund = ChooseEq.create()
                .when(apiDataExchangeParameter.getProvidentFund(), "1", 0)
                .when(apiDataExchangeParameter.getProvidentFund(), "2", 1)
                .when(apiDataExchangeParameter.getProvidentFund(), "3", 2)
                .when(apiDataExchangeParameter.getProvidentFund(), "4", 1)
                .end(0);
        data.setFund(fund);
        // 保单：1.无保单 3.缴纳未满一年 4.缴纳一年以上
        Integer policy = ChooseEq.create()
                .when(apiDataExchangeParameter.getInsurancePolicy(), "1", 1)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "2", 3)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "3", 4)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "4", 3)
                .end(1);
        data.setInsurance(policy);
        // 车产情况： 1-无车产 2-有车产可抵押 3-有车不抵押
        Integer car = ChooseEq.create()
                .when(apiDataExchangeParameter.getCarInfo(), "1", 1)
                .when(apiDataExchangeParameter.getCarInfo(), "2", 3)
                .when(apiDataExchangeParameter.getCarInfo(), "3", 2)
                .when(apiDataExchangeParameter.getCarInfo(), "4", 3)
                .end(1);
        data.setCar(car);
        // 房产情况：2-无房产 12-有房可抵押 13-有房不抵押
        Integer house = ChooseEq.create()
                .when(apiDataExchangeParameter.getRealEstateInfo(), "1", 2)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "2", 13)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "3", 12)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "4", 13)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "5", 13)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "6", 13)
                .end(2);
        data.setHouse(house);
        // 职业：1.民企员工 2.个体户  4.自由职业者 5.企业主  7.外企员工 8.公务员 9.事业单位员工 10.国企员工
        Integer job = ChooseEq.create()
                .when(apiDataExchangeParameter.getCareer(), "1", 1)
                .when(apiDataExchangeParameter.getCareer(), "2", 4)
                .when(apiDataExchangeParameter.getCareer(), "3", 5)
                .when(apiDataExchangeParameter.getCareer(), "4", 8)
                .when(apiDataExchangeParameter.getCareer(), "5", 2)
                .end(4);
        data.setProfession(job);
        // 营业执照：1.没办理 2.已办理，注册1年以内 3.已办理，注册满1年 4.已办理，注册满2年 5.已办理，注册满3年 6.已办理，注册满4年 7.已办理，注册满5年以上
        Integer bizLicenseYear = ChooseEq.create()
                .when(apiDataExchangeParameter.getBizLicenseYear(), "1", 1)
                .when(apiDataExchangeParameter.getBizLicenseYear(), "2", 2)
                .when(apiDataExchangeParameter.getBizLicenseYear(), "3", 3)
                .when(apiDataExchangeParameter.getBizLicenseYear(), "4", 7)
                .end(1);
        data.setBusinessLicense(bizLicenseYear);
        //  信用卡:1.3000以下 2.3000-10000元 3.10000-30000元  4.30000元以上 5.无信用卡 6.有(额度未知)
        Integer creditCard = ChooseEq.create()
                .when(apiDataExchangeParameter.getCreditLimit(), "1", 5)
                .when(apiDataExchangeParameter.getCreditLimit(), "2", 1)
                .when(apiDataExchangeParameter.getCreditLimit(), "3", 2)
                .when(apiDataExchangeParameter.getCreditLimit(), "4", 3)
                .when(apiDataExchangeParameter.getCreditLimit(), "5", 4)
                .when(apiDataExchangeParameter.getCreditLimit(), "6", 6)
                .end(0);
        data.setCreditLimit(creditCard);
        //  是否有逾期 0:当前无逾期 1:逾期一月内 2:逾期三个月内 3:逾期超过三个月
        Integer overdue = ChooseEq.create()
                .when(apiDataExchangeParameter.getOverdue(), "1", 0)
                .when(apiDataExchangeParameter.getOverdue(), "2", 1)
                .when(apiDataExchangeParameter.getOverdue(), "3", 0)
                .end(1);
        data.setOverdue(overdue);
        //  芝麻分：2、600分以下   3、600-650分 4、650-700分   5、700分及以上
        Integer zhima = ChooseEq.create()
                .when(apiDataExchangeParameter.getSesameCredit(), "1", 2)
                .when(apiDataExchangeParameter.getSesameCredit(), "2", 3)
                .when(apiDataExchangeParameter.getSesameCredit(), "3", 4)
                .when(apiDataExchangeParameter.getSesameCredit(), "4", 5)
                .end(0);
        data.setZhima(zhima);
        //  月收入：1.1000以下 2.1000-3000  3.3000-5000  4.5000-8000  5.8000-1.2万  6.1.2万-2万  7.2万-5万  8.5万-10万  9.10万以上
        Integer monthlySalary = ChooseEq.create()
                .when(apiDataExchangeParameter.getMonthlySalary(), "1", 2)
                .when(apiDataExchangeParameter.getMonthlySalary(), "2", 3)
                .when(apiDataExchangeParameter.getMonthlySalary(), "3", 4)
                .when(apiDataExchangeParameter.getMonthlySalary(), "4", 5)
                .when(apiDataExchangeParameter.getMonthlySalary(), "5", 7)
                .end(1);
        data.setIncomeMonth(monthlySalary);
        //  工资发放形式：1-银行代发  3-现金发放
        Integer wages = ChooseEq.create()
                .when(apiDataExchangeParameter.getSalaryPayMethod(), "1", 1)
                .when(apiDataExchangeParameter.getSalaryPayMethod(), "2", 3)
                .when(apiDataExchangeParameter.getSalaryPayMethod(), "3", 3)
                .end(1);
        data.setSalaryType(wages);
        // 用户真实IP
        if (ValidParam.isNotEmpty(apiDataExchangeParameter.getIp())) {
            data.setIp(apiDataExchangeParameter.getIp());
        } else {
            data.setIp("127.0.0.1");
        }
        return MapUtils.<String, Object>newHashMap(newMap -> {
            newMap.put("channelCode", CHANNEL_CODE);
            newMap.put("data", AES.createCbc(KEY.getBytes(), IV.getBytes()).encryptToBase64Str(JsonUtils.toJson(data)));
        });
    }


    @Override
    public Object apply(ApiApplyParameter apiApplyParameter) throws Exception {
        apiApplyParameter.setHttpContentType(HttpContentType.APPLICATION_JSON);
        ApiPlatApplyHuiRongQianBao data = new ApiPlatApplyHuiRongQianBao();
        // 请求编号,与撞库请求同一请求ID
        data.setRequestId(CHANNEL_CODE + "+" + apiApplyParameter.getReqId());
        // 姓名 需传全名
        data.setUserName(apiApplyParameter.getUserName());
        // 手机号明文
        data.setPhone(apiApplyParameter.getPhone());
        ApiFieldConverter apiFieldConverter = ApiFieldConverter.create(apiApplyParameter);
        // 性别 男/女
        data.setSex(apiFieldConverter.getSexText());
        // 年龄
        data.setAge(apiFieldConverter.getAgeInt());
        // 学历 :-1.初中及以下 0.高中/中专 1.大专 2.本科 3.硕士 4.博士
        Integer education = ChooseEq.create()
                .when(apiApplyParameter.getEducationAttainment(), "1", -1)
                .when(apiApplyParameter.getEducationAttainment(), "2", 0)
                .when(apiApplyParameter.getEducationAttainment(), "3", 0)
                .when(apiApplyParameter.getEducationAttainment(), "4", 1)
                .when(apiApplyParameter.getEducationAttainment(), "5", 2)
                .when(apiApplyParameter.getEducationAttainment(), "6", 3)
                .end(-1);
        data.setEducation(education);
        // 城市编码，详见城市列表
        data.setCity(apiApplyParameter.getAreaCode());
        // 金额(万元)
        Integer money = ChooseEq.create()
                .when(apiApplyParameter.getLoanAmount(), "1", 3)
                .when(apiApplyParameter.getLoanAmount(), "2", 5)
                .when(apiApplyParameter.getLoanAmount(), "3", 10)
                .when(apiApplyParameter.getLoanAmount(), "4", 20)
                .end();
        data.setLoanAmt(money);
        // 期限：1. 1个月 2. 3个月 3. 6个月 4. 9个月 5. 12个月 6. 24个月 7. 36个月 8. 36个月以上 默认 12个月
        data.setLoanTerm(1);
        Integer loanPurpose = ChooseEq.create()
                .when(apiApplyParameter.getLoanPurpose(), "1", 8)
                .when(apiApplyParameter.getLoanPurpose(), "2", 4)
                .when(apiApplyParameter.getLoanPurpose(), "3", 7)
                .when(apiApplyParameter.getLoanPurpose(), "4", 3)
                .when(apiApplyParameter.getLoanPurpose(), "5", 9)
                .when(apiApplyParameter.getLoanPurpose(), "6", 10)
                .end(10);
        data.setLoanUse(loanPurpose);
        // 用户真实IP
        if (ValidParam.isNotEmpty(apiApplyParameter.getIp())) {
            data.setIp(apiApplyParameter.getIp());
        } else {
            data.setIp("127.0.0.1");
        }
        //  社保： 0.无社保 1.缴纳未满6个月 2.缴纳6个月以上
        Integer social = ChooseEq.create()
                .when(apiApplyParameter.getSocialSecurity(), "1", 0)
                .when(apiApplyParameter.getSocialSecurity(), "2", 1)
                .when(apiApplyParameter.getSocialSecurity(), "3", 2)
                .when(apiApplyParameter.getSocialSecurity(), "4", 1)
                .end(0);
        data.setSocial(social);

        //  公积金： 0.无公积金 1.缴纳未满6个月 2.缴纳6个月以上
        Integer fund = ChooseEq.create()
                .when(apiApplyParameter.getProvidentFund(), "1", 0)
                .when(apiApplyParameter.getProvidentFund(), "2", 1)
                .when(apiApplyParameter.getProvidentFund(), "3", 2)
                .when(apiApplyParameter.getProvidentFund(), "4", 1)
                .end(0);
        data.setFund(fund);
        //  保单：1.无保单 3.缴纳未满一年 4.缴纳一年以上
        Integer policy = ChooseEq.create()
                .when(apiApplyParameter.getInsurancePolicy(), "1", 1)
                .when(apiApplyParameter.getInsurancePolicy(), "2", 3)
                .when(apiApplyParameter.getInsurancePolicy(), "3", 4)
                .when(apiApplyParameter.getInsurancePolicy(), "4", 3)
                .end(1);
        data.setInsurance(policy);
        //  车产情况： 1-无车产 2-有车产可抵押 3-有车不抵押
        Integer car = ChooseEq.create()
                .when(apiApplyParameter.getCarInfo(), "1", 1)
                .when(apiApplyParameter.getCarInfo(), "2", 3)
                .when(apiApplyParameter.getCarInfo(), "3", 2)
                .when(apiApplyParameter.getCarInfo(), "4", 3)
                .end(1);
        data.setCar(car);
        //  房产情况：2-无房产 12-有房可抵押 13-有房不抵押
        Integer house = ChooseEq.create()
                .when(apiApplyParameter.getRealEstateInfo(), "1", 2)
                .when(apiApplyParameter.getRealEstateInfo(), "2", 13)
                .when(apiApplyParameter.getRealEstateInfo(), "3", 12)
                .when(apiApplyParameter.getRealEstateInfo(), "4", 13)
                .when(apiApplyParameter.getRealEstateInfo(), "5", 13)
                .when(apiApplyParameter.getRealEstateInfo(), "6", 13)
                .end(2);
        data.setHouse(house);
        //  职业：1.民企员工 2.个体户  4.自由职业者 5.企业主 7.外企员工 8.公务员 9.事业单位员工 10.国企员工
        Integer job = ChooseEq.create()
                .when(apiApplyParameter.getCareer(), "1", 1)
                .when(apiApplyParameter.getCareer(), "2", 4)
                .when(apiApplyParameter.getCareer(), "3", 5)
                .when(apiApplyParameter.getCareer(), "4", 8)
                .when(apiApplyParameter.getCareer(), "5", 2)
                .end(4);
        data.setProfession(job);
        // 营业执照：1.没办理 2.已办理，注册1年以内 3.已办理，注册满1年 4.已办理，注册满2年 5.已办理，注册满3年 6.已办理，注册满4年 7.已办理，注册满5年以上
        Integer bizLicenseYear = ChooseEq.create()
                .when(apiApplyParameter.getBizLicenseYear(), "1", 1)
                .when(apiApplyParameter.getBizLicenseYear(), "2", 2)
                .when(apiApplyParameter.getBizLicenseYear(), "3", 3)
                .when(apiApplyParameter.getBizLicenseYear(), "4", 7)
                .end(1);
        data.setBusinessLicense(bizLicenseYear);
        //  信用卡:1.3000以下 2.3000-10000元 3.10000-30000元  4.30000元以上 5.无信用卡 6.有(额度未知)
        Integer creditCard = ChooseEq.create()
                .when(apiApplyParameter.getCreditLimit(), "1", 5)
                .when(apiApplyParameter.getCreditLimit(), "2", 1)
                .when(apiApplyParameter.getCreditLimit(), "3", 2)
                .when(apiApplyParameter.getCreditLimit(), "4", 3)
                .when(apiApplyParameter.getCreditLimit(), "5", 4)
                .when(apiApplyParameter.getCreditLimit(), "6", 6)
                .end(0);
        data.setCreditLimit(creditCard);
        //  是否有逾期 0:当前无逾期 1:逾期一月内 2:逾期三个月内 3:逾期超过三个月
        Integer overdue = ChooseEq.create()
                .when(apiApplyParameter.getOverdue(), "1", 0)
                .when(apiApplyParameter.getOverdue(), "2", 1)
                .when(apiApplyParameter.getOverdue(), "3", 0)
                .end(1);
        data.setOverdue(overdue);
        //  芝麻分：2、600分以下   3、600-650分 4、650-700分   5、700分及以上
        Integer zhima = ChooseEq.create()
                .when(apiApplyParameter.getSesameCredit(), "1", 2)
                .when(apiApplyParameter.getSesameCredit(), "2", 3)
                .when(apiApplyParameter.getSesameCredit(), "3", 4)
                .when(apiApplyParameter.getSesameCredit(), "4", 5)
                .end(0);
        data.setZhima(zhima);
        //  月收入：1.1000以下 2.1000-3000  3.3000-5000  4.5000-8000  5.8000-1.2万  6.1.2万-2万  7.2万-5万  8.5万-10万  9.10万以上
        Integer monthlySalary = ChooseEq.create()
                .when(apiApplyParameter.getMonthlySalary(), "1", 2)
                .when(apiApplyParameter.getMonthlySalary(), "2", 3)
                .when(apiApplyParameter.getMonthlySalary(), "3", 4)
                .when(apiApplyParameter.getMonthlySalary(), "4", 5)
                .when(apiApplyParameter.getMonthlySalary(), "5", 7)
                .end(1);
        data.setIncomeMonth(monthlySalary);
        // 撞库返回的productId
        data.setProductId(Integer.valueOf(apiApplyParameter.dataExchangeApplyId()));
        //  工资发放形式：1-银行代发  3-现金发放
        Integer wages = ChooseEq.create()
                .when(apiApplyParameter.getSalaryPayMethod(), "1", 1)
                .when(apiApplyParameter.getSalaryPayMethod(), "2", 3)
                .when(apiApplyParameter.getSalaryPayMethod(), "3", 3)
                .end(1);
        data.setSalaryType(wages);
        // 用户信息授权协议，静态文件流，参数动态请求不支持协议。支持多个协议地址用逗号隔开
        data.setAgreementUrl(H5DomainUrlUtils.createUserProtocolUrl(apiApplyParameter.getProductPlanId(), apiApplyParameter.getPhoneMd5()));

        return JsonUtils.toJson(MapUtils.<String, Object>newHashMap(newMap -> {
            newMap.put("channelCode", CHANNEL_CODE);
            newMap.put("data", AES.createCbc(KEY.getBytes(), IV.getBytes()).encryptToBase64Str(JsonUtils.toJson(data)));
        }));
    }

    @Override
    public RespPlatformPhoneMaskApply respApply(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformPhoneMaskApply.ofFail();
        }
        String code = jsonObject.getString("code");
        if (!Eq.str(code, "200")) {
            return RespPlatformPhoneMaskApply.ofFail();
        }
        String status = jsonObject.getJSONObject("data").getString("status");
        if (!Eq.str(status, "1")) {
            return RespPlatformPhoneMaskApply.ofFail();
        }
        return RespPlatformPhoneMaskApply.ofSuc();
    }
}
